<?php

namespace common\services\config;

use common\repositories\config\MyscrmFunctionupgradeRepository;
use common\entities\config\MyscrmFunctionupgradeEntity;
use common\services\BaseService;
use common\services\project\MyapplicationtoprojectService;

/**
 * Summary of MyscrmFunctionupgradeService
 * @property bool $ydxsNewModel 移动销售是否使用新模型
 */
class MyscrmFunctionupgradeService extends BaseService
{
    private $_myscrmFunctionupgradeRepository;

    public function __construct()
    {
        $this->_myscrmFunctionupgradeRepository = new MyscrmFunctionupgradeRepository();
    }


    /**
     * 根据organizationId获取数据
     * @return array|bool|\yii\db\ActiveRecord[]
     */
    public function getOrganizationData()
    {
        return $this->_myscrmFunctionupgradeRepository->getDataByOrganizationId($this->_myscrmFunctionupgradeRepository->getUserIdentity()->orgId);
    }

    /**
     * 获取哪些租户升级了指定的功能
     * @param string $functionName 功能名称
     * @param int $functionMode 功能值
     */
    public function getUpgradeOrganizations($functionName,$functionMode = 2)
    {
        return $this->_myscrmFunctionupgradeRepository->getUpgradeOrganizations($functionName,$functionMode);
    }

    /**
     * 判断租户是否升级了拓客中心
     * @param $token  公众号Token
     * @return bool
     */
    public function hasTouKeUpgrade($token){
        return $this->_myscrmFunctionupgradeRepository->hasTouKeUpgrade($token);
    }

    /**
     * 根据租户id与方法名，判断功能是否升级
     * @param mixed $organizationId 租户id
     * @param mixed $functionName 方法名称
     * @return boolean
     * @author wangwx
     */
    public function isUpgrade($organizationId, $functionName)
    {
        return $this->_myscrmFunctionupgradeRepository->isUpgrade($organizationId,$functionName);
    }

    /**
     * 获取升级了功能的租户列表
     * @param string $functionName 功能名称
     * @param string $functionMode 功能值
     * @return array
     */
    public function getOrgListByFunctionNameAndMode($functionName,$functionMode = 2){
        return $this->_myscrmFunctionupgradeRepository->getOrgListByFunctionNameAndMode($functionName,$functionMode);
    }

    /**
     * 获取升级了功能且绑定了ERP的租户列表
     * @param string $functionName 功能名称
     * @param string $functionMode 功能值
     * @return array
     */
    public function getBindErpOrgListByFunctionNameAndMode($functionName,$functionMode = 2){
        return $this->_myscrmFunctionupgradeRepository->getBindErpOrgListByFunctionNameAndMode($functionName,$functionMode);
    }

    public function getYdxsNewModel()
    {
        return $this->_myscrmFunctionupgradeRepository->hasOrganizationUpgrade($this->userContextService->uniqueId, '移动销售新模型');
    }

    public function enableFunction($orgId, $functionName)
    {
        return $this->_myscrmFunctionupgradeRepository->enableFunction($orgId, $functionName);
    }

    public function disableFunction($orgId, $functionName)
    {
        return $this->_myscrmFunctionupgradeRepository->disableFunction($orgId, $functionName);
    }
}